perf: use VLB and make methods sync in EventReceiverOrchestrator#4410
perf: use VLB and make methods sync in EventReceiverOrchestrator#4410thomhurst merged 1 commit intothomhurst:mainfrom
VLB and make methods sync in EventReceiverOrchestrator#4410Conversation
SummaryPerformance optimization using ValueListBuilder for allocation reduction and making methods synchronous. Critical IssuesMissing try-finally in RegisterReceivers (line 41-77): The ValueListBuilder is only disposed if no exception occurs. This could leak array pool buffers. VerdictREQUEST CHANGES - Need try-finally block around VLB usage. |
Detailed FixIn EventReceiverOrchestrator.RegisterReceivers, the ValueListBuilder needs try-finally: Before: vlb.Dispose() only runs if no exception occurs This prevents leaking array pool buffers when exceptions occur during event object enumeration or registration. Performance NotesThe changes are excellent for performance:
The only minor point is the duplicated early-exit logic in InvokeTestEndEventReceiversAsync, but the performance benefit likely justifies it. |
ValueListBuilderinRegisterReceiversBefore
After
Fun fact:
Attribute.EqualsandAttribute.GetHashCodeallocate aFieldInfo[]each time they are called.